<?php

use Illuminate\Database\Seeder;
use \Illuminate\Support\Facades\DB;

class AdminMenuSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $menus = [
            [
                'parent_id' => 0,
                'title' => 'users',
                'icon' => 'fa-users',
                'uri' => '',
                'permission' => 'users',
                'children' => [
                    [
                        'title' => 'user_infos',
                        'icon' => 'fa-floppy-o',
                        'uri' => 'users',
                        'permission' => 'users',
                    ],
                    [
                        'title' => 'top_up_apply',
                        'icon' => 'fa-cc-paypal',
                        'uri' => 'top_up_apply',
                        'permission' => 'users',
                    ],
                ],
            ],
            [
                'parent_id' => 0,
                'title' => 'banners',
                'icon' => 'fa-image',
                'uri' => 'banners',
                'permission' => 'banners',
            ],
            [
                'parent_id' => 0,
                'title' => 'sellers',
                'icon' => 'fa-shopping-bag',
                'uri' => '',
                'permission' => 'sellers',
                'children' => [
                    [
                        'title' => 'sellers',
                        'icon' => 'fa-black-tie',
                        'uri' => 'sellers',
                        'permission' => 'sellers',
                    ],
                    [
                        'title' => 'shops',
                        'icon' => 'fa-shopping-cart',
                        'uri' => 'shops',
                        'permission' => 'sellers',
                    ],
                    [
                        'title' => 'products',
                        'icon' => 'fa-server',
                        'uri' => 'products',
                        'permission' => 'sellers',
                    ],
                    [
                        'title' => 'withdraws',
                        'icon' => 'fa-credit-card',
                        'uri' => 'withdraws',
                        'permission' => 'sellers',
                    ],
                ],
            ],
            [
                'parent_id' => 0,
                'title' => 'address',
                'icon' => 'fa-map-marker',
                'uri' => 'address',
                'permission' => 'address',
                'children' => [
                    [
                        'title' => 'sys_province',
                        'icon' => 'fa-list-ol',
                        'uri' => 'sys_province',
                        'permission' => 'address',
                    ],
                    [
                        'title' => 'sys_city',
                        'icon' => 'fa-list-ol',
                        'uri' => 'sys_city',
                        'permission' => 'address',
                    ],
                    [
                        'title' => 'sys_district',
                        'icon' => 'fa-list-ol',
                        'uri' => 'sys_district',
                        'permission' => 'address',
                    ],
                ],
            ],
            [
                'parent_id' => 0,
                'title' => 'log_balance',
                'icon' => 'fa-database',
                'uri' => 'log_balance',
                'permission' => 'log_balance',
            ],
            [
                'parent_id' => 0,
                'title' => 'forum',
                'icon' => 'fa-comments',
                'uri' => 'forum',
                'permission' => 'forum',
                'children' => [
                    [
                        'title' => 'news',
                        'icon' => 'fa-newspaper-o',
                        'uri' => 'news',
                        'permission' => 'forum',
                    ],
                    [
                        'title' => 'posts',
                        'icon' => 'fa-newspaper-o',
                        'uri' => 'posts',
                        'permission' => 'forum',
                    ],
                    [
                        'title' => 'comments',
                        'icon' => 'fa-comments-o',
                        'uri' => 'comments',
                        'permission' => 'forum',
                    ],
                    [
                        'title' => 'gag_list',
                        'icon' => 'fa-ban',
                        'uri' => 'gag_list',
                        'permission' => 'forum',
                    ],
                ],
            ],
            [
                'parent_id' => 0,
                'title' => 'orders',
                'icon' => 'fa-cart-plus',
                'uri' => 'orders',
                'permission' => 'orders',
            ],
            [
                'parent_id' => 0,
                'title' => 'help_center',
                'icon' => 'fa-gavel',
                'uri' => 'help_center',
                'permission' => 'help_center',
            ],
            [
                'parent_id' => 0,
                'title' => 'exchange_rates',
                'icon' => 'fa-percent',
                'uri' => 'exchange_rates',
                'permission' => 'exchange_rates',
            ],
            [
                'parent_id' => 0,
                'title' => 'pay_method',
                'icon' => 'fa-dollar',
                'uri' => 'pay_method',
                'permission' => 'pay_method',
            ],
        ];

        foreach ($menus as $data) {
            if (isset($data['children']) && $data['children']) {
                $children = $data['children'];
                unset($data['children']);
                $id = DB::table('admin_menu')->insertGetId($data);

                foreach ($children as $child) {
                    $child['parent_id'] = $id;
                    DB::table('admin_menu')->insert($child);
                }

            } else {
                DB::table('admin_menu')->insert($data);
            }
        }
    }
}
